package com.bwie.controller;

import com.bwie.bo.SpuBo;
import com.bwie.pojo.SpuDetail;
import com.bwie.service.SpuService;
import com.bwie.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: day0423-pxx
 * @ClassName SpuController
 * @description:
 * @author: 段阳
 * @create: 2024-04-29 21:25
 **/
@RestController
@RequestMapping("item/spu")
public class SpuController {

    @Autowired
    private SpuService spuService;

    @GetMapping("/page")
    public ResponseEntity<PageResult<SpuBo>> findSpuList(
            @RequestParam(required = false ) String key,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "5") Integer rows,
            @RequestParam(required = false) Boolean saleable
    ){
        return spuService.findSpuList(key,page,rows,saleable);
    }
    @GetMapping("detail/{spuId}")
    public ResponseEntity<SpuDetail> getSpuDetail(@PathVariable(name = "spuId") Long spuId){
       SpuDetail spuDetail = spuService.getSpuDetail(spuId);
       return ResponseEntity.ok(spuDetail);
    }

}